#pragma once
#include<iostream>
#include<vector>
#include<stdbool.h>
using namespace std;
namespace bit
{
   
    template<class T>
    struct less
    {
        bool operator()(T& a,T& b)
        {
            return a < b;
        }
    };
    template<class T>
    struct greater
    {
        bool operator()(T& a, T& b)
        {
            return a > b;
        }
    };
    template <class T, class Container = vector<T>, class Compare = less<T> >
    class priority_queue
    {
    public:
        priority_queue()
        {}
        template <class InputIterator>
        priority_queue(InputIterator first, InputIterator last)
        {
            while (first != last)
            {
                c.push(*first);
                first++;
            }
        }
        bool empty() 
        {
            return c.empty();
        }
       
        size_t size() const
        {
            return c.size();
        }
        T top() const
        {
            return c[0];
        }
        void AdjustUp(int child)
        {
            int parent = (child - 1) / 2;
            while (child > 0)
            {
                parent = (child - 1) / 2;
                if (comp(c[parent], c[child]))
                {
                    swap(c[parent], c[child]);
                    child = parent;
                }
                else
                {
                    break;
                }
            }
        }
        void push(const T& x)
        {
            c.push_back(x);
            AdjustUp(c.size() - 1);
        }
        void AdjustDown(size_t parent)
        {
            int child = parent * 2 + 1;

            while (child < c.size())
            {
                if (child + 1 < c.size() && comp(c[child], c[child + 1]))
                    child++;
                if (comp(c[parent], c[child]))
                {
                    swap(c[parent], c[child]);
                    parent = child;
                }
                else
                {
                    break;
                }
            }
        }
        void pop()
        {
            swap(c[0], c[c.size() - 1]);
            c.pop_back();
            AdjustDown(0);
        }
    private:
        Container c;
        Compare comp;

    };

};